package com.copa.l509;

/**
 * @author copa
 * @createDate 2022-06-28 17:22
 * @function 动态规划法
 */
public class Test3 {

    public int fib(int n) {
        if (n < 2) {
            return n == 1 ? 1 : 0;
        }
        int left = 0;
        int right = 1;
        int result = 1;
        for (int i = 2; i < n; i++) {
            left = right;
            right = result;
            result = left + right;
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(new Test3().fib(5));
    }
}
